﻿/************************************************************************

	File:			pak_io.h
	Version:		1.0
	Changes:		A
	Author:			Stanley Lau
	Date:			2010.07.26
	Purpose:		File IO Module Cross-platform Functions Declaration

************************************************************************/

#ifndef _PAK_KERNEL_COMMON_IO_H_
#define _PAK_KERNEL_COMMON_IO_H_

#include <stdio.h>
#include "pak_io_crossplat.h"

//	Brief:				Open one file according the pstrMode
//	pstrFileName:		The file's name to open
//	pstrMode:			The mode how to open the file "r" "w" "b" "a"
//	return:				if success return the pointer to the FILE otherwise return NULL;
//FILE* _OpenFile( const char* pstrFileName, const char* pstrMode );

//	Brief:				Read file at the current file position
//	hFile:				The file pointer to read
//	pstrReadBuffer:		The buffer to get the read contents
//	nReadBufferLen:		The buffer len
//	pnReadLen:			The read len,after function return,it value indicate the real read len
//	return:				if success return 1 otherwise return 0
int _ReadFile( FILE* hFile, char* pstrReadBuffer, size_t nReadLen, size_t* pnReadLen );

//	Brief:				Read file at the specify file position
//	hFile:				The file pointer to read
//	pstrReadBuffer:		The buffer to get the read contents
//	nReadLen:			The length to read
//	pnReadLen:			The read len,after function return,it value indicate the real read len
//	lPos:				The file position to start read
//	return:				if success return 1 otherwise return 0
int _ReadFileAt( FILE* hFile, char* pstrReadBuffer, size_t nReadLen, size_t* pnReadLen, long lPos );

//	Brief:				Write file at the current file position
//	hFile:				The file pointer to write
//	pstrWriteBuffer:	The buffer to give the write contents
//	nWriteLen:			The length to write
//	pnWriteLen:			The write len,after function return,it value indicate the real write len
//	return:				if success return 1 otherwise return 0
int _WriteFile( FILE* hFile, char* pstrWriteBuffer, size_t nWriteLen, size_t* pnWriteLen );

//	Brief:				Write file at the current file position
//	hFile:				The file pointer to write
//	pstrWriteBuffer:	The buffer to give the write contents
//	pnWriteLen:			The write len,after function return,it value indicate the real write len
//	lPos:				The file position to start write
//	return:				if success return 1 otherwise return 0
int _WriteFileAt( FILE* hFile, char* pstrWriteBuffer, size_t nWriteLen, size_t* pnWriteLen, long lPos );

//	Brief:				Set file position 
//	hFile:				The file to set
//	lFilePos:			The relative position
//	iBegin:				The start position
//	return:				if success return 1 otherwise return 0
int _SetFilePos( FILE* hFile, long lFilePos, int iBegin );

//	Brief:				Get file position 
//	hFile:				The file to get
//	lFilePos:			The relative position
//	return:				if success return 1 otherwise return 0
int _GetFilePos( FILE* hFile, long* plFilePos );

//	Brief:				Get file size 
//	hFile:				The file size to get
//	plSize:				The pointer to long variable to get the size of the file
//	return:				if success return 1 otherwise return 0
int _GetFileSize( FILE* hFile, long* plSize );

//	Brief:				Close file
//	hFile:				The file pointer to close
//	return:				if success return 1 otherwise return 0
int _CloseFile( FILE* hFile );

#endif
//Last line for linux

